package org.javaboy.rpc_server.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    public static final String RPC_EXCHANGE = "rpc_exchange";
    public static final String SEND_MSG_QUEUE = "send_msg_queue";
    public static final String REPLY_MSG_QUEUE = "reply_msg_queue";

    @Bean
    Binding sendMsgBinding() {
        return BindingBuilder.bind(sendMsgQueue()).to(rpcExchange()).withQueueName();
    }

    @Bean
    Binding replyMsgBinding() {
        return BindingBuilder.bind(replyMsgQueue()).to(rpcExchange()).withQueueName();
    }

    @Bean
    DirectExchange rpcExchange() {
        return new DirectExchange(RPC_EXCHANGE, true, false);
    }

    @Bean
    Queue replyMsgQueue() {
        return new Queue(REPLY_MSG_QUEUE, true, false, false);
    }

    @Bean
    Queue sendMsgQueue() {
        return new Queue(SEND_MSG_QUEUE, true, false, false);
    }

}
